<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head th:include="public/page_css::page_css ('收货人详情查看')"/>
<meta charset="UTF-8"/>
<title>Title</title>
<!-- load css -->

<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/css/font/iconfont.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/js/layui/css/layui.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}" media="all"/>
<body>
<div id="div2">
    <div class="layui-fluid larry-wrapper">
        <!-- <div style=" margin-left: 10px;font-weight: bold;">
             <h4> 收货地址管理</h4>
             <hr/>
         </div>-->
        <div class="layui-card">
            <form id="form1" class="layui-form layui-form-pane" action="">
                <div>&nbsp;</div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">详细地址</label>
                        <div class="layui-input-inline">
                            <input type="text" name="xxdz" id="xxdz" placeholder="详细地址" lay-verify="required"
                                   autocomplete="off" class="layui-input "/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">联系人姓名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="lxr" id="lxr" placeholder="联系人姓名" lay-verify="required"
                                   autocomplete="off" class="layui-input "/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">联系人电话</label>
                        <div class="layui-input-inline">
                            <input type="text" name="lxdh" id="lxdh" placeholder="联系人电话"
                                   lay-verify="required|phone|number" autocomplete="off" class="layui-input "/>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">

                    <div class="layui-inline">
                        <label class="layui-form-label">省份</label>
                        <div class="layui-input-inline">
                            <select name="sheng" id="sheng2" lay-verify="required" lay-filter="sheng2">

                            </select>
                        </div>
                        <!-- <div class="layui-input-inline">
                             <input type="text" name="sheng" id="sheng" placeholder="省份" autocomplete="off" class="layui-input "/>
                         </div>-->
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">城市</label>
                        <div class="layui-input-inline">
                            <select name="shi" id="shi2" lay-verify="required">
                            </select>
                        </div>
                        <!--<div class="layui-input-inline">
                            <input type="text" name="shi" id="shi" placeholder="城市" autocomplete="off" class="layui-input "/>
                        </div>-->
                    </div>
                </div>
                <input type="hidden" th:value="${sskhid}" id="sskhid1" name="sskhid">
                <input type="hidden" id="id" name="id">
                <div style="  border-bottom: 1px solid; border-bottom-color: #d5cece; padding: 20px;">
                    <!--  <a class="layui-btn layui-btn-sm layui-btn-normal " id="addbtn">
                          <i class="layui-icon">&#x1005;</i> 添加
                      </a>
                      <a class="layui-btn layui-btn-sm" id="savebtn">
                          <i class="layui-icon">&#x1005;</i> 保存编辑
                      </a>-->
                    <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="addbtn">添加
                    </button>
                    <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="savebtn">保存编辑
                    </button>
                </div>
            </form>
            <div>

                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline" style="width: 190px">
                        <label class="layui-form-label" style=" width: 100px;">详细地址</label>
                        <div class="layui-inline">
                            <input type="text" name="xxdz" placeholder="详细地址" class="layui-input" style="width: 190px">
                        </div>
                    </div>
                    <div class="layui-inline" style="width: 190px">
                        <label class="layui-form-label" style=" width: 100px;">联系人</label>
                        <div class="layui-inline">
                            <input type="text" name="lxr" placeholder="联系人" class="layui-input" style="width: 190px">
                        </div>
                    </div>

                    <div class="layui-inline inline-search-btn" style="  margin-top: 40px; margin-left: 40px;">
                        <a class="layui-btn layui-btn-normal" data-type="reload" id="search_button"> 搜索 </a>
                    </div>
                    <div class="layui-inline inline-reset-btn" style="  margin-top: 40px;">
                        <button type="reset" class="layui-btn layui-btn-primary" style="background-color: #40AFFE">重置
                        </button>
                    </div>
                </form>
                <div class="layui-col-xs24" style="max-height: 300px;overflow: auto">
                    <table data-height="300" id="table1" style="word-break:break-all; word-wrap:break-word;"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" th:src="@{/plugin/layui/js/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/plugin/layui/js/version.js}"></script>
<script th:src="@{/plugin/layui/js/common.js}"></script>
<div th:include="public/public_js::public_js"></div>
<script>
    $(function () {

        //加载省份
        $("#sheng,#sheng2").html("");
        var str = "<option value=''>==请选择===</option>";
        $.ajax({
            type: "GET",
            url: "/zxsswms/wmscityinfo/selectProvice/1",
            dataType: "JSON",
            async: false,
            success: function (data) {
                console.info(data);
                //从服务器获取数据进行绑定
                $.each(data, function (i, item) {
                    console.info("item.cityname" + item.cityname);
                    console.info(item.citycode);
                    str += "<option value=" + item.cityname + " code=" + item.citycode + ">" + item.cityname + "</option>";
                })
                //将数据添加到省份这个下拉框里面
                $("#sheng").append(str);
                $("#sheng2").append(str);

            },
            error: function () {
                alert("Error");
            }
        });
    });

</script>

<script>
    //	回车查询
    document.onkeydown = function (event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
            $('#search_button2').click();
        }
    };

    function cityBind() {
        var sheng = $("#sheng").attr("value");
        console.info("sheng" + sheng);
        //判断省份这个下拉框选中的值是否为空
        if (sheng == "") {
            return;
        }
        $("#shi").html("");
        var str = "<option value=''>==请选择===</option>";
        $.ajax({
            type: "POST",
            url: "/xbzzwms/wmscityinfo/selectProvice/" + sheng,
            dataType: "JSON",
            async: false,
            success: function (data) {
                //从服务器获取数据进行绑定
                $.each(data, function (i, item) {
                    str += "<option value=" + item.citycode + ">" + item.cityname + "</option>";
                })
                //将数据添加到省份这个下拉框里面
                $("#shi").append(str);
            },
            error: function () {
                alert("Error");
            }
        });
    }

    layui.use(['myform', 'zzpUtils', 'form'], function () {
        var form = layui.form,
            zzpUtils = layui.zzpUtils;


        form.on('select(sheng2)', function (data) {
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            var sheng = $("#sheng2").find("option:selected").attr("code");
            //判断省份这个下拉框选中的值是否为空
            if (sheng == "") {
                return;
            }

            $("#shi2").html("");
            var str = "<option value=''>==请选择===</option>";
            $.ajax({
                type: "GET",
                url: "/zxsswms/wmscityinfo/selectProvice/" + sheng,
                dataType: "JSON",
                async: false,
                success: function (data) {
                    //从服务器获取数据进行绑定
                    $.each(data, function (i, item) {
                        str += "<option value=" + item.cityname + ">" + item.cityname + "</option>";
                    })
                    console.info(str);
                    //将数据添加到省份这个下拉框里面
                    $("#shi2").append(str);
                    console.info("第三方斯蒂芬");
                    console.info($("#shi2").html());
                    form.render('select');
                },
                error: function () {
                    alert("Error");
                }
            });

        });
        window.operateEvent = {
            //地址编辑
            "click #editRow": function (e, value, row, index) {
                console.info(row);
                $.ajax({
                    type: 'get',
                    url: '/zxsswms/wmsCustomerFileConsignee/findOne/' + row.id,
                    contentType: "application/json",
                    async: false,
                    success: function (data) {
                        $("#xxdz").val(data.xxdz);
                        $("#lxr").val(data.lxr);
                        $("#lxdh").val(data.lxdh);
                        //$('#sheng2').html('<option value="' + data.sheng + '">' + data.sheng + '</option>').trigger("change");
                        /*  var optionInf = optionRendering(data.sheng, 'sheng', 'sheng');*/
                        $("#sheng2").val(data.sheng);
                        var str;
                        $.ajax({
                            type: "GET",
                            url: "/zxsswms/wmscityinfo/getIdByName/" + data.sheng,
                            dataType: "JSON",
                            async: false,
                            success: function (data) {
                                $.ajax({
                                    type: "GET",
                                    url: "/zxsswms/wmscityinfo/selectProvice/" + data.citycode,
                                    dataType: "JSON",
                                    async: false,
                                    success: function (data) {
                                        //从服务器获取数据进行绑定
                                        $.each(data, function (i, item) {
                                            str += "<option value=" + item.cityname + ">" + item.cityname + "</option>";
                                        })
                                        console.info(str);
                                        //将数据添加到省份这个下拉框里面
                                        $("#shi2").append(str);
                                        console.info("第三方斯蒂芬");
                                        console.info($("#shi2").html());
                                        form.render('select');
                                    },
                                    error: function () {
                                        alert("Error");
                                    }
                                });
                            },
                            error: function () {
                                alert("Error");
                            }
                        });

                        $('#shi2').val(data.shi);
                        form.render();
                        $("#id").val(data.id);
                        $("#sskhid1").val(data.sskhid);
                        /*  zzpUtils.loadJsonDataToForm(data);*/
                        console.log(data);
                    }
                })

            },
            //地址启用
            "click #enable": function (e, value, row, index) {
                layer.confirm('您将启用该收货地址。', {icon: 3, title: '确认启用？'}, function (index) {
                    var id = [];
                    id.push(row.id);
                    $.ajax({
                        type: 'post',
                        url: '/zxsswms/wmsCustomerFileConsignee/activation',
                        contentType: "application/json",
                        async: false,
                        data: JSON.stringify({
                            ids: id,
                        }),
                        success: function (res) {
                            console.log(res);
                            setTimeout(function () {
                                /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                 parent.layer.close(index); //再执行关闭
                                 console.info(data);*/
                                top.layer.msg(res.title + "," + res.message);
                                zzpUtils.refreshTable("#table1");
                                //刷新父页面
                            }, 500);
                        }
                    })
                    layer.close(index);
                });

            },
            //地址删除
            "click #deleteBtn": function (e, value, row, index) {
                layer.confirm('您将作废该收货地址。', {icon: 3, title: '确认作废？'}, function (index) {
                    console.log('触发了删除', index, row, value);
                    var tabledata = $table1.bootstrapTable('getData');
                    tabledata = tabledata.filter(function (item) {
                        return item.uuid !== row.uuid;
                    });
                    var id = [];
                    id.push(row.id);
                    $.ajax({
                        type: 'post',
                        url: '/zxsswms/wmsCustomerFileConsignee/cancel',
                        contentType: "application/json",
                        async: false,
                        data: JSON.stringify({
                            ids: id,
                        }),
                        success: function (res) {
                            setTimeout(function () {
                                zzpUtils.refreshTable("#table1");
                                /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                 parent.layer.close(index); //再执行关闭
                                 console.info(data);*/
                                top.layer.msg(res.title + "," + res.message);
                                //刷新父页面
                            }, 500);
                        }
                    })
                    layer.close(index);
                })
            },
            //取消默认
            "click #default": function (e, value, row, index) {
                layer.confirm('您将信息设为默认。', {icon: 3, title: '确认设为默认？'}, function (index) {
                    $.ajax({
                        type: 'get',
                        url: '/zxsswms/wmsCustomerFileConsignee/acquiesceIn/' + row.id,
                        contentType: "application/json",
                        async: false,
                        success: function (data) {
                            setTimeout(function () {
                                zzpUtils.refreshTable("#table1");
                                /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                 parent.layer.close(index); //再执行关闭
                                 console.info(data);*/
                                top.layer.msg(res.title + "," + res.message);
                                //刷新父页面
                            }, 500);
                        },
                        error: function () {
                            alert("Error");
                        }
                    });
                    layer.close(index);
                })
            },
            //默认
            "click #undefault": function (e, value, row, index) {
                layer.confirm('您将信息取消默认。', {icon: 3, title: '确认取消默认？'}, function (index) {
                    $.ajax({
                        type: 'get',
                        url: '/zxsswms/wmsCustomerFileConsignee/removeAcquiesceIn/' + row.id,
                        contentType: "application/json",
                        async: false,
                        success: function (data) {
                            setTimeout(function () {
                                zzpUtils.refreshTable("#table1");
                                /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                 parent.layer.close(index); //再执行关闭
                                 console.info(data);*/
                                top.layer.msg(res.title + "," + res.message);
                                //刷新父页面
                            }, 500);
                        },
                        error: function () {
                            alert("Error");
                        }
                    });
                    layer.close(index);
                })
            },


        }

        var $table1 = zzpUtils.table({
            elem: '#table1',
            isApi: true,
            pagination: true,
            url: '/wmsCustomerFileConsignee/list/' + $("#sskhid1").val(),
            columns: [
                {
                    field: '',
                    checkbox: true,
                    clickToSelect: true
                }, {
                    field: 'num',
                    title: '序号',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                }, {
                    field: 'xxdz',
                    title: '详细地址',
                }, {
                    field: 'lxr',
                    title: '联系人姓名'
                }, {
                    field: 'lxdh',
                    title: '联系人电话'
                }, {
                    field: 'sheng',
                    title: '省份',
                }, {
                    field: 'shi',
                    title: '城市',
                }, {
                    field: 'caozuo',
                    title: '操作',
                    events: operateEvent,
                    formatter: operateFormatter
                }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
        });

        function operateFormatter(value, row, index) {
            if (row.sfyx == 0) {//无效
                return [
                    '<a class="layui-btn layui-btn-xs " id="enable">启用</a>',
                ].join('')
            } else {
                if (row.sfmr == 0) {//非默认
                    return [
                        '<a class="layui-btn layui-btn-xs " id="editRow">编辑</a>',
                        '<a class="layui-btn layui-btn-xs " id="default">默认</a>',
                        '<a class="layui-btn layui-btn-danger layui-btn-xs " id="deleteBtn">作废</a>',

                    ].join('')
                } else if (row.sfmr == 1) {//默认
                    return [
                        '<a class="layui-btn layui-btn-xs " id="editRow">编辑</a>',
                        '<a class="layui-btn layui-btn-xs " id="undefault">取消默认</a>',
                        '<a class="layui-btn layui-btn-danger layui-btn-xs " id="deleteBtn">作废</a>',
                    ].join('')
                }

            }
        }

        $(".inline-search-btn").on('click', function () {
            zzpUtils.refreshTable("#table1");
        })

        //收货地址编辑保存
        /*  $("#savebtn").on('click', function () {
         var formObject = {};
         var formArray =$("#form1").serializeArray();
         $.each(formArray,function(i,item){
         formObject[item.name] = item.value;
         });
         var formJson = JSON.stringify(formObject);
         alert(formJson);
         var ids = [];
         var tabledata = $table1.bootstrapTable('getData');
         console.log('tabledata', tabledata);
         $.ajax({
         type: 'post',
         url: '/zxsswms/wmsCustomerFileConsignee/edit',
         contentType: "application/json",
         async: false,
         data: formJson,
         success: function (res) {
         /!*   zzpUtils.refreshTable("#table1");*!/
         $('#table1').bootstrapTable('refresh',{url:'/zxsswms/wmsCustomerFileConsignee/list/'+$("#sskhid1").val()});
         setTimeout(function(){
         /!*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
         parent.layer.close(index); //再执行关闭
         console.info(data);*!/
         top.layer.msg(res.title+","+res.message);

         //刷新父页面
         },500);
         }

         })


         });*/
        form.on("submit(savebtn)", function (data) {
            var formObject = {};
            var formArray = $("#form1").serializeArray();
            $.each(formArray, function (i, item) {
                formObject[item.name] = item.value;
            });
            var formJson = JSON.stringify(formObject);
            var ids = [];
            var tabledata = $table1.bootstrapTable('getData');
            var sheng = $("#sheng2").val();
            var shi = $("#shi2").val();
            $.ajax({
                type: 'post',
                url: '/zxsswms/wmsCustomerFileConsignee/edit',
                contentType: "application/json",
                async: false,
                data: formJson,
                success: function (res) {
                    /*   zzpUtils.refreshTable("#table1");*/
                    $('#table1').bootstrapTable('refresh', {url: '/zxsswms/wmsCustomerFileConsignee/list/' + $("#sskhid1").val()});
                    setTimeout(function () {
                        $('#form1')[0].reset();
                        /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                         parent.layer.close(index); //再执行关闭
                         console.info(data);*/
                        top.layer.msg(res.title + "," + res.message);

                        //刷新父页面
                    }, 500);
                }
            })
            var tabledata = $table1.bootstrapTable('getData');
            console.log('tabledata', tabledata);
            zzpUtils.refreshTable("#table1");
            return false;

        });


        //删除多选行
        $("#delBtn").on('click', function () {
            $rows = $table1.bootstrapTable('getSelections');
            var tabledata = $table1.bootstrapTable('getData');
            if ($rows.length == 0) {
                layer.msg("请选择一条进行删除");
            } else {

                var id = [];
                $rows.forEach(function (item) {
                    id.push(item.id);
                })
                $.ajax({
                    type: 'post',
                    url: '/zxsswms/wmsCustomerFileConsignee/cancel',
                    contentType: "application/json",
                    async: false,
                    data: JSON.stringify({
                        ids: id,
                    }),
                    success: function (res) {
                        console.info(res);
                        setTimeout(function () {
                            zzpUtils.refreshTable("#table1");
                            /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                             parent.layer.close(index); //再执行关闭
                             console.info(data);*/
                            top.layer.msg(res.title + "," + res.message);
                            //刷新父页面
                        }, 500);
                    }
                })
                /*  $table1.bootstrapTable('remove', {field: 'id', values: id});

                 $table1.bootstrapTable('load', tabledata);*/
            }
//            console.log($rows);
        });
        //收货地址添加一行
        /* $("#addbtn").on('click',function () {
         alert($("#sskhid1").val());
         var isRepeat;
         var row={"uuid":Math.random().toString(36),"xxdz":$("#xxdz").val(),"lxr":$("#lxr").val(),"lxdh":$("#lxdh").val(),"sheng":$("#sheng2").val(),"shi":$("#shi2").val(),"sskhid":$("#sskhid1").val()}
         /!*$table1.bootstrapTable('append', row);*!/
         $.ajax({
         type: 'post',
         url: '/zxsswms/wmsCustomerFileConsignee/save',
         contentType: "application/json",
         async: false,
         data: JSON.stringify(row),
         success: function (res) {
         alert("addbtn:"+$("#sskhid1").val());
         /!* zzpUtils.refreshTable("#table1");*!/
         $('#table1').bootstrapTable('refresh',{url:'/zxsswms/wmsCustomerFileConsignee/list/'+$("#sskhid1").val()});
         alert("addbtnss:"+$("#sskhid1").val());
         setTimeout(function(){
         /!*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
         parent.layer.close(index); //再执行关闭
         console.info(data);*!/
         top.layer.msg(res.title+","+res.message);
         //刷新父页面
         },500);
         }
         })

         var tabledata = $table1.bootstrapTable('getData');
         console.log('tabledata', tabledata);
         zzpUtils.refreshTable("#table1");

         /!* if (tabledata.length ===0) {
         $table1.bootstrapTable('append', $rows);
         } else {
         for (var i=0;i<$rows.length;i++){
         isRepeat = tabledata.every(function (item) {
         return (item.id !== $rows[i].id)
         });
         if (!isRepeat){
         break;
         }
         }
         console.log('isRepeat', isRepeat);
         if (isRepeat) {
         $table1.bootstrapTable('append', $rows);
         } else {
         layer.msg('已存在不能重复添加');
         }
         }*!/
         });*/

        form.on("submit(addbtn)", function (data) {
            var isRepeat;
            var row = {
                "uuid": Math.random().toString(36),
                "xxdz": $("#xxdz").val(),
                "lxr": $("#lxr").val(),
                "lxdh": $("#lxdh").val(),
                "sheng": $("#sheng2").val(),
                "shi": $("#shi2").val(),
                "sskhid": $("#sskhid1").val()
            }
            /*$table1.bootstrapTable('append', row);*/
            $.ajax({
                type: 'post',
                url: '/zxsswms/wmsCustomerFileConsignee/save',
                contentType: "application/json",
                async: false,
                data: JSON.stringify(row),
                success: function (res) {
                    /* zzpUtils.refreshTable("#table1");*/
                    $('#table1').bootstrapTable('refresh', {url: '/zxsswms/wmsCustomerFileConsignee/list/' + $("#sskhid1").val()});
                    setTimeout(function () {
                        $('#form1')[0].reset();
                        /*  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                         parent.layer.close(index); //再执行关闭
                         console.info(data);*/
                        top.layer.msg(res.title + "," + res.message);
                        //刷新父页面
                    }, 500);
                }
            })

            //  zzpUtils.refreshTable("#table1");
            return false;
        });


    });

</script>
</html>